<?php

namespace app\admin\controller;
use app\admin\model\MemberMatrix as MemberMatrixModel;
use app\admin\model\Member as MemberModel;

class Matrix extends Admin
{
    /*
 	* @Description  数据列表
 	*/
    function index(){
        if (!$this->request->isPost()){
            return view('index');
        }else{
            $limit  = $this->request->post('limit', 20, 'intval');
            $page = $this->request->post('page', 1, 'intval');

            $where = [];
            $where['mid'] = $this->request->post('mid', '', 'serach_in');

            $order  = $this->request->post('order', '', 'serach_in');	//排序字段
            $sort  = $this->request->post('sort', '', 'serach_in');		//排序方式

            $orderby = ($sort && $order) ? $sort.' '.$order : 'id desc';

            $res = MemberMatrixModel::getList(formatWhere($where),$page,$limit,$orderby);

            foreach ($res['data'] as $k => $v){
                $member = MemberModel::getDetails($v['mid']);
                $res['data'][$k]['user'] = '';
                if(!empty($member)){
                    $res['data'][$k]['user'] = $v['mid'].' | '.$member['username'];
                }
            }

            $data['status'] = 200;
            $data['data'] = $res;
            return json($data);
        }
    }
}